package cn.lrwjz.geotest.ui;

import android.os.Bundle;
import android.os.StatFs;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.appbar.MaterialToolbar;

import java.util.ArrayList;

import cn.lrwjz.geotest.R;

public class ProjectMangerActivity extends AppCompatActivity {
    TextView tv_capacity_value;
    RecyclerView recycler_project_list;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_manger);
        // 设置工具栏
        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("项目管理");
        }
        tv_capacity_value=findViewById(R.id.tv_capacity_value);
//        列表
        recycler_project_list=findViewById(R.id.recycler_project_list);
//        获取项目列表
        reloadProjectList();
        // 获取磁盘容量
        getDiskCapacity();
    }

    private void reloadProjectList() {
        ArrayList<String> projectList = new ArrayList<>();

    }

    private void getDiskCapacity() {
        StatFs statFs = new StatFs(getFilesDir().getAbsolutePath());
        long totalBytes = (long) statFs.getBlockCount() * statFs.getBlockSize();
        long availableBytes = (long) statFs.getAvailableBlocks() * statFs.getBlockSize();
        long usedBytes = totalBytes - availableBytes;

        // 转换为 GB
        double totalGB = totalBytes / (1024.0 * 1024.0 * 1024.0);
        double usedGB = usedBytes / (1024.0 * 1024.0 * 1024.0);
        Log.d("DiskCapacity", "总容量: " + totalGB + " GB");
        Log.d("DiskCapacity", "已使用: " + usedGB + " GB");

        // 格式化为一位有效小数并设置到 TextView
        String capacityInfo = String.format("%.1f GB\n/%.1f GB",usedGB, totalGB);
        tv_capacity_value.setText(capacityInfo);
    }
}